<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    div {
      padding: 50px;
    }

    #div1 {
      background-color: red;
    }

    #div2 {
      background-color: yellow;
    }

    #div3 {
      background-color: blue;
    }
  </style>
</head>

<body>
  <div id="div1">
    <div id="div2">
      <div id="div3">
      </div>
    </div>
  </div>
  <script>
    var divs = document.getElementsByTagName("div")
    for (var i = 0; i < divs.length; i++) {
      divs[i].onclick = function(ev) {
        var e = ev || window.event
        var target = e.target || window.event.srcElement
        alert(target.id)
        // alert(this.id)
        // e.cancelBubble=true
      }
    }
  </script>
</body>

</html>